using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;

public class TurretCard : MonoBehaviour
{
    public static Action<TurretSettings> OnPlaceTurret;// 放置炮塔时的事件
    public TurretSettings TurretLoaded { get; set; }// 载入的炮塔设置信息
    [SerializeField]
    private Image turretImage; // 炮塔图片
    [SerializeField]
    // private TextMeshProUGUI turretCost; // 炮塔价格文本

    public void SetupTurretButton(TurretSettings turretSettings)
    {
        TurretLoaded = turretSettings;
        turretImage.sprite = turretSettings.turretShopSprite; // 设置炮塔图片
        // turretCost.text = turretSettings.turretShopCost.ToString(); // 设置炮塔价格文本
    }

    // 放置炮塔的方法
    public void PlaceTurret()
    {
        // 检查玩家金币是否足够购买炮塔
        if (CurrencySystem.Instance.TotalCoins >= TurretLoaded.turretShopCost)
        {
            // 扣除对应金币
            CurrencySystem.Instance.RemoveCoins(TurretLoaded.turretShopCost);
            UIManager.Instance.CloseTurretShopPanel();
            // 触发放置炮塔事件，传递炮塔设置信息
            OnPlaceTurret?.Invoke(TurretLoaded);
        }
    }
}
